package com.qzsoft.zhjd.common.utils;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import org.springframework.beans.BeanUtils;

public class PageConvertUtils {
    public static <T> IPage<T> sourceToTarget(IPage<?> dataPage, Class<T> target) {
        if (ObjectUtil.isNull(dataPage)) {
            return null;
        }
        List<?> sourceList = dataPage.getRecords();
        List<T> targetList = ConvertUtils.sourceToTarget(sourceList, target);
        IPage<T> targetPage = new Page<>();
        targetPage.setRecords(targetList);
        BeanUtils.copyProperties(dataPage, targetPage, new String[] { "records" });
        return targetPage;
    }
}
